import com.interfaces.IA;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class TestAB {
    public static void main(String[] args) {
        A  a = new A(); //旧的类
        B  b   = new B();
        IA obj = (IA) Proxy.newProxyInstance(a.getClass().getClassLoader(), a.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                method.invoke(a,args);//a.go1()
                b.go2();
                return null;
            }
        });
        obj.go1();

    }
}
